<template>
	<view>
		<view class="address-box add-box">
			<view class="add-img-box">
				<view class="add-img-item" v-for="(item, index) in imgList" :key="index">
					<image class="add-img" @click="imgInfo(index)" :src="item.path" mode="aspectFill"></image>
					<image  class="add-img-del" @click="delImg(index)" src="@/static/img/delete.png"></image>
				</view>
				<view v-if="imgList.length < 9 " class="add-img-item" @click="openCamera">
					<image class="add-img" src="@/static/img/add.png"></image>
				</view>
			</view>
		</view>
<!-- 		<view  @click="submit" class="address-box submit-box">
			<text class="submit-btn">上传服务器</text>
		</view> -->
	</view>
</template>

<script>


export default {
	data() {
		return {
			imgList: [],
			cloudimgList: [],
			imgCount: 9,//最多支持9张上传，可以修改
		};
	},
	onLoad(e) {		
	},
	methods: {
		submit(e) {
			this.submitData = null;
			if (this.imgList.length < 1) {
				uni.showToast({
					title: '请添加图片',
					icon: 'none'
				});
				return false;
			}
			uni.showLoading({
				title: '上传图片',
				mask: false
			});
			// for (let i = 0; i < this.imgList.length; i++) {
			// 	console.log("test！"+this.imgList[i].path);			
			// 	this.$cloud.uploadFile({
			// 		filePath: this.imgList[i].path,
			// 		success: (res) => {
			// 			//保存图片的路径
			// 			this.cloudimgList.push(res.fileID);
			// 		},
			// 		fail: (err) => {
			// 			console.log(err);
			// 		},
			// 		complete: () => {
			// 			//uni.hideLoading();
			// 			if (this.cloudimgList.length == this.imgList.length) {
			// 				uni.hideLoading();
			// 				uni.showToast({
			// 					title: '全部上传成功！',
			// 					icon: 'none'
			// 				});
			// 			}
			// 		}
			// 	})
			// 	}
		},
			
		imgInfo(i) {
			let tempList = [];
			this.imgList.forEach(img => {
				tempList.push(img.path);
			});
			console.log(tempList);
			//显示图片
			uni.previewImage({
				current: i,
				loop: false,
				urls: tempList,
				indicator: 'default'
			});
		},
		delImg(i) {
			uni.showModal({
				content: '确定删除这张吗',
				success: res => {
					if (res.confirm) {
						this.imgList.splice(i, 1);
						this.imgCount++;
					} else if (res.cancel) {
						
					}
				}
			});
		},
		openCamera() {
			uni.chooseImage({
				sourceType:['camera'],
				count: this.imgCount,
				sizeType: ['compressed'],
				success: e => {
					this.imgList = [...this.imgList, ...e.tempFiles];

					this.imgCount = 9 - this.imgList.length;
					console.log('imgCount', this.imgCount);
				}
			});
		},
								
	}
};
</script>

<style lang="scss">
.back {
	font-size: 32rpx;
	font-weight: 500;
	line-height: 48rpx;
	color: rgba(153, 153, 153, 1);
}
.back-hover {
	opacity: 0.4;
}
.submit-box {
	position: fixed;
	bottom: 0;
	left: 0;
	display: flex;
	width: 750rpx;
	justify-content: center;
}
.submit-btn {
	margin-top: 10px;
	display: inline-block;
	width: 670rpx;
	height: 96rpx;
	line-height: 96rpx;
	text-align: center;
	background-color: rgba(109, 221, 203, 1);
	opacity: 1;
	border-radius: 32rpx;
	border-width: 8rpx;
	border-color: rgba(255, 255, 255, 1);
	box-shadow: 0rpx 8rpx 12rpx rgba(0, 0, 0, 0.16);
	border-radius: 56rpx;
	font-size: 39rpx;
	font-weight: bold;
	color: rgba(255, 255, 255, 1);
}
.submit-btn-txt {
	font-size: 39rpx;
	font-weight: bold;
	line-height: 47rpx;
	color: rgba(255, 255, 255, 1);
	opacity: 1;
}
.map-box {
	width: 484rpx;
	height: 256rpx;
	border-width: 4rpx;
	border-color: rgba(255, 255, 255, 1);
	box-shadow: 0rpx 0rpx 24rpx rgba(0, 0, 0, 0.16);
	/* border-radius: 12rpx; */
	position: relative;
}
.map {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	width: 476rpx;
	height: 250rpx;
}
.map-img {
	position: absolute;
	top: 90rpx;
	left: 156rpx;
	width: 230rpx;
	height: 68rpx;
	background-color: rgba(51, 51, 51, 0.64);
	border-width: 1rpx;
	border-color: rgba(0, 0, 0, 0);
	border-radius: 34px;

	font-size: 28rpx;
	font-weight: bold;
	line-height: 66rpx;
	color: rgba(255, 255, 255, 1);
	text-align: center;
}
.address-box {
	display: flex;
	width: 670rpx;
	flex-direction: row;
	align-items: center;
	justify-content: space-between;
	padding: 15rpx 40rpx;
	margin-bottom: 10px;
}
.label {
	font-size: 36rpx;
	font-weight: bold;
	line-height: 50rpx;
	color: #222222;
}
.label-img {
	padding-left: 40rpx;
}
.address-box-txt {
	align-items: flex-start;
}
.address-txt {
	width: 484rpx;
	height: 90rpx;
	font-size: 32rpx;
	font-weight: 500;
	line-height: 45rpx;
	color: rgba(51, 51, 51, 1);
}
.add-box {
	padding: 15rpx 0;
	flex-wrap: wrap;
}
.add-img-box {
	display: flex;
	width: 750rpx;
	//padding: 0 40rpx;
	flex-direction: row;
	flex-wrap: wrap;
}
.add-img-item {
	/* width:210rpx;
		height:210rpx; */
	width: 200rpx;
	height: 150rpx;
	border-radius: 24rpx;
	position: relative;
	padding: 9rpx 0;
	margin-left: 20rpx;
}
.add-img-camera {
	flex: 1;
}
.add-img {
	width: 200rpx;
	height: 150rpx;
	border-radius: 14rpx;
}
.add-img-del {
	position: absolute;
	width: 40rpx;
	height: 40rpx;
	right: 8rpx;
	top: 17rpx;
	//background-color: rgba(238, 0, 0, 1);
	border-radius: 20rpx;
}
.address-time {
	width: 484rpx;
	height: 88rpx;
	background-color: rgba(245, 245, 245, 1);
	opacity: 1;
	border-radius: 24rpx;
	text-align: center;

	font-size: 35rpx;
	font-weight: 500;
	color: rgba(51, 51, 51, 1);
}
.line{
	width: 750rpx;
	height: 1px;
	transform: scaleY(0.3);
	background-color: rgba(0,0,0,0.5);
}
</style>
